<?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;

class LoginController extends BaseController
{
    //登录界面
    public function index()
    {
        return view('backend.login.index');
    }
    //登录行为
    public function login()
    {
        //验证
        $this->validate(\request(),[
            'username'=>'required|string|min:5|max:10',
            'password'=>'required|string'
        ]);
        //逻辑
        $param=\request(['username','password']);
        if(\Auth::guard('admin')->attempt($param)){
            return redirect('/'.config('website.route.prefix.admin'));
        }
        //渲染
        return back()->withErrors('用户名密码不匹配');
    }
    //登出
    public function logout()
    {
        \Auth::guard('admin')->logout();
        return \redirect('/'.config('website.route.prefix.admin').'/login');
    }
}
